package com.pig.client;

import com.pig.api.User;
import com.pig.api.UserService;
import com.pig.client.utils.ProxyUtils;
import com.pig.rpc.dto.RpcReq;
import com.pig.rpc.dto.RpcResp;
import com.pig.rpc.proxy.RpcClientProxy;
import com.pig.rpc.transmission.RpcClient;
import com.pig.rpc.transmission.socket.client.SocketRpcClient;
import com.pig.rpc.util.ThreadPoolUtils;

import java.util.concurrent.ExecutorService;

public class Main {

    public static void main(String[] args) {
        UserService userService = ProxyUtils.getProxy(UserService.class);
        User user = userService.getUser(1L);
        System.out.println(user);

//        RpcClient rpcClient = new RpcClient() {
//            @Override
//            public RpcResp<?> sendReq(RpcReq req) {
//
//                return null;
//            }
//        };
//        RpcReq req = RpcReq.builder()
//                .reqId("1213")
//                .interfaceName("com.pig.api.UserService")
//                .methodName("getUser")
//                .params(1L)
//                .paramTypes(Long.class)
//                .build();

//        RpcResp<?> rpcResp = rpcClient.sendReq(req);
//
//        User user = (User)rpcResp.getData();
//        System.out.println(user);


//                RpcClient rpcClient = new SocketRpcClient("127.0.0.1",8888);
//
//                RpcReq req = RpcReq.builder()
//                        .reqId("1213")
//                        .interfaceName("com.pig.api.UserService")
//                        .methodName("getUser")
//                        .params(new Object[]{1L})
//                        .paramTypes(new Class[]{Long.class})
//                        .build();
//
//                RpcResp<?> rpcResp = rpcClient.sendReq(req);
//
//                System.out.println(rpcResp.getData());



        //return (T)rpcResp.getData();
    }

//    private static <T> T getProxy(Class<T> clazz) {
//        RpcClient rpcClient = new SocketRpcClient("127.0.0.1", 8888);
//        RpcClientProxy rpcClientProxy = new RpcClientProxy(rpcClient);
//        return rpcClientProxy.getProxy(clazz);
//    }


}
